<template>
	<page-body>
		<view class="page">
			<view class="flex benben-position-layout flex flex-wrap align-center details_flex_0_higd"
				:style="{height:(88+StatusBarRpx)+'rpx',paddingTop:StatusBarRpx+'rpx', }">
				<view class='flex flex-wrap align-center justify-between flex-sub details_fd0_0_higd'>
					<view class='flex flex-wrap align-center details_fd0_0_c0_higd' @tap.stop="handleJumpDiy"
						data-type="back" data-url="1">
						<text class='fu-iconfont2  details_fd0_0_c0_c0_higd'>&#xE794;</text>
					</view>
					<view class='flex flex-wrap align-stretch justify-center'>
						<text class='details_fd0_0_c1_c0_higd'></text>
					</view>
					<view class='flex flex-wrap align-center justify-end details_fd0_0_c0_higd'>
					</view>
				</view>

			</view>
			<view :style="{height: (88+StatusBarRpx)+'rpx'}"></view>
			<!---flex布局flex布局开始-->
			<view class="flex flex-direction align-stretch benben-flex-layout details_flex_1_higd">
				<view class='flex flex-wrap align-center details_fd1_0_higd'>
					<text class='details_fd1_0_c0_higd'>{{info.title}}</text>
				</view>
				<view class='flex flex-wrap align-center details_fd1_1_higd'>
					<text>发布时间:{{info.fbsj}}</text>
					<text class='details_fd1_1_c1_higd'>{{$t('浏览量：')}}</text>
					<text>{{info.liulanl}}</text>
				</view>
				<view class='flex flex-wrap align-center details_fd1_1_higd'>
					<text class=''>{{$t('来源：')}}</text>
					<text>{{info.ly}}</text>
				</view>
				<view class="list" v-if="type==2 && info.file.length !=0">
					<view class="flex item" v-for="(item,index) in info.file" :key='index'>
						<view>{{item.name}}</view>
						<view class="down" @click="download(item)">下载</view>
					</view>

				</view>
				<jyf-parser class='details_fd1_2_higd' :html="info.content | richTextFormat">
				</jyf-parser>
			</view>

			<!---flex布局flex布局结束-->


		</view>
	</page-body>
</template>
<script>
	import {
		validate
	} from '@/common/utils/validate.js'

	export default {
		components: {},


		data() {
			return {
				/** fbsj【发布时间】
				 *   ly【来源】
				 *   content【内容】
				 *   liulanl【浏览量】
				 *   title【标题】 **/
				"info": {
					"title": "",
					"liulanl": "",
					"content": "",
					"ly": "",
					"fbsj": "",
					file: []
				},
				"id": "",
				"type": ""
			};
		},
		computed: {

		},
		watch: {},
		onLoad(options) {
			let {
				id,
				type
			} = options
			if (id !== undefined) this.id = id
			if (type !== undefined) this.type = type
			this.getinfoFunc()
		},
		onUnload() {

		},
		onReady() {

		},
		onShow() {

		},
		onHide() {

		},
		onResize() {

		},
		onPullDownRefresh() {

		},
		onReachBottom(e) {

		},
		onPageScroll(e) {

		},
		methods: {
			//查询制度防建设详情
			async getbq73449f35a144Func() {
				//请求方法
				//数据验证

				let datainfo = await this.$api.get(global.apiUrls.post673449f35a144, {
					aid: this.id
				});

				if (datainfo.data.code != 1) {
					this.$message.info(datainfo.data.msg);
					return
				}
				let infoinfo = datainfo.data;
				this.info = infoinfo.data
				console.log(this.info)

			},
			//查询安全知识详情
			async getio7385f39b5e34Func() {
				//请求方法
				//数据验证

				let datainfo = await this.$api.get(global.apiUrls.post67385f39b5e34, {
					aid: this.id
				});

				if (datainfo.data.code != 1) {
					this.$message.info(datainfo.data.msg);
					return
				}
				let infoinfo = datainfo.data;
				this.info = infoinfo.data


			},
			//获取数据
			getinfoFunc() {
				if (this.type == '1') {
					this.getio7385f39b5e34Func()
				} else {
					this.getbq73449f35a144Func()
				}
			},
			download(item) {
				console.log(item.path)
				  // #ifdef APP-PLUS
				  // 下载并打开文件
				  uni.downloadFile({
				    url: item.path,
				    success: (res) => {
						console.log(res)
				      if (res.statusCode === 200) {
				        uni.saveFile({
				          tempFilePath: res.tempFilePath,
				          success: (saveRes) => {
							  console.log(saveRes)
				            console.log('文件保存成功', saveRes.savedFilePath);
				            uni.showToast({ title: '下载成功' });
							   plus.runtime.openFile(saveRes.savedFilePath, {}, function(e) {
							  uni.showToast({ title: '打开文件失败', icon: 'none' });
							});
				          }
				        });
				      }
				    }
				  });
				  return
				  // #endif
				  // #ifdef H5
				  const link = document.createElement('a');
				  link.href = item.path;
				  link.download = item.name || item.path.split('/').pop();
				  link.style.display = 'none';
				  
				  document.body.appendChild(link);
				  link.click();
				  document.body.removeChild(link);
				  
				  // 微信浏览器特殊处理
				  if (/MicroMessenger/i.test(navigator.userAgent)) {
				    // uni.showModal({
				    //   title: '下载提示',
				    //   content: '请点击右上角菜单，选择"在浏览器中打开"进行下载',
				    //   showCancel: false
				    // });
				  } 
				  return
				  // #endif
				    // #ifdef MP-WEIXIN
				    uni.downloadFile({
				      url: item.path,
				      success: (res) => {
						  console.log(res)
						   let tempFilePath= res.tempFilePath
						   uni.saveFile({
						     tempFilePath: tempFilePath,
						     success: (saveRes) => {
								 this.$message.info('文件已保存到:'+saveRes.savedFilePath)
								   setTimeout(() => {
								    uni.openDocument({
										  filePath:saveRes.savedFilePath,
										  success: ()=>{
											 
										  }
										});
								   }, 1000);
								 
						     }
						   });
				        
				      }
				    });
					return
				    // #endif
			return
				uni.downloadFile({
					url: item.path,
					success: function(res) {
						if (res.statusCode === 200) {
						  uni.saveFile({
						    tempFilePath: res.tempFilePath,
						    success: (saveRes) => {
						      console.log('文件保存成功', saveRes.savedFilePath);
						      uni.showToast({ title: '下载成功' });
						    }
						  });
						}
						
						
						const filePath = res.tempFilePath;
						uni.hideLoading(); // 隐藏loading提示框
						  // #ifdef H5
						  this.$message.info('h5下载')
						  // 创建隐藏的下载链接
						  const link = document.createElement('a');
						  link.href = filePath;
						  link.target = '_blank';
						  link.download = filePath.split('/').pop(); // 获取文件名
						  
						  // 触发点击
						  document.body.appendChild(link);
						  link.click();
						  document.body.removeChild(link);
						  return
						  // #endif
						uni.openDocument({
							filePath: filePath,
							showMenu: true, //右上角是否有可以转发分享的功能
							success: function() {
								console.log('打开文档成功');
							},
							fail: function(err) {
								console.error('打开文档失败', err);
								uni.showToast({
									title: '打开文档失败',
									icon: 'none',
								})
							}
						});
					},
					fail: function(err) {
						console.error('下载文件失败', err);
					}
				});

			}
		}
	};
</script>
<style lang="scss" scoped>
	.page {
		width: 100vw;
		overflow-x: hidden;
		min-height: calc(100vh - var(--window-bottom));
		background: rgba(255, 255, 255, 1);
		background-size: 100% auto;

		.details_flex_1_higd {
			padding: 32rpx;

			.details_fd1_0_higd {
				margin: 0rpx 0rpx 20rpx 0rpx;

				.details_fd1_0_c0_higd {
					font-size: 40rpx;
					font-weight: 500;
				}
			}

			.details_fd1_1_higd {
				margin: 0rpx 0rpx 32rpx 0rpx;
			}
		}

		.details_fd1_1_c1_higd {
			margin: 0rpx 0rpx 0rpx auto;
		}

		.details_flex_0_higd {
			width: 750rpx;
			height: 88rpx;
			overflow: hidden;
			z-index: 10;
			top: 0rpx;
			background: #fff;
			background-size: 100% auto !important;

			.details_fd0_0_higd {
				padding: 0rpx 32rpx 0rpx 32rpx;

				.details_fd0_0_c1_c0_higd {
					font-size: 36rpx;
					font-weight: 700;
					color: #333333;
					line-height: 50rpx;
				}
			}
		}

		.details_fd0_0_c0_higd {
			width: 120rpx;

			.details_fd0_0_c0_c0_higd {
				font-size: 36rpx;
				color: #333;
			}
		}
	}

	::v-deep .details_fd1_2_higd {
		width: 100%;
	}

	.list {
		width: 100%;

		.item {
			margin: 24rpx 0;
			font-size: 32rpx;
			text-align: center;

			.down {
				width: 120rpx;
				height: 64rpx;
				line-height: 64rpx;
				background-color: #d32a29;
				color: #fff;
				text-align: center;
				margin-left: auto;
				border-radius: 12rpx;
			}
		}
	}
</style>
